package com.qh.resourcehub.program.virtual.controller;

import com.qh.resourcehub.program.dto.VirtualDto;
import com.qh.resourcehub.program.virtual.service.VirtualService;
import com.qh.resourcehub.program.vo.VirtualVo;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//青海省气象信息中心虚拟化资源池服务器申请变更表（运行保障室） 01
@RestController
@RequestMapping("/virtualApply")
public class VirtualApplyController {
    @Autowired
    private VirtualService virtualService;
    /*
     * @Description:
     * @param 查询申请信息
     * @return
     * @Author: Y6
     * @Date: 2025/4/18 14:19
     */
    @PostMapping("/queryVirtualData")
    public ApiResponse queryVirtualData(@RequestBody VirtualDto virtualDto) {
        try {
            List<VirtualVo> data = virtualService.queryVirtualData(virtualDto);
            if (data.size()>0){
                return ApiResponse.succeed(data);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("查询失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * IP申请新增
     * @param
     * @return
     */
    @PostMapping("/ApplicationSave")
    public ApiResponse ApplicationSave(@RequestBody VirtualDto virtualDto) {
        try {
            int i = virtualService.ApplicationSave(virtualDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * IP申请修改
     * @param
     * @return
     */
    @PostMapping("/ApplicationUpdata")
    public ApiResponse ApplicationUpdata(@RequestBody VirtualDto virtualDto) {
        try {
            int i = virtualService.ApplicationUpdata(virtualDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
    /**
     * IP申请删除
     * @param
     * @return
     */
    @PostMapping("/Applicationdel")
    public ApiResponse Applicationdel(@RequestBody VirtualDto virtualDto) {
        try {
            int i = virtualService.Applicationdel(virtualDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**examine
     * 虚拟资源申请提交
     * @param
     * @return
     */
    @PostMapping("/ApplicationSubmit")
    public ApiResponse ApplicationSubmit(@RequestBody VirtualDto virtualDto) {
        try {
            int i = virtualService.ApplicationSubmit(virtualDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }

    /**
     * 虚拟资源申请撤回
     * @param
     * @return
     */
    @PostMapping("/ApplicationWithdraw")
    public ApiResponse ApplicationWithdraw(@RequestBody VirtualDto virtualDto) {
        try {
            int i = virtualService.ApplicationWithdraw(virtualDto);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            e.printStackTrace(); // 打印完整堆栈信息
            return ApiResponse.succeedRequestErr("操作失败: " + e.getMessage()); // 返回详细错误信息
        }
    }
}
